class SegTree:
def __init__(self, a):
self.n = len(a)
self.t = [0]*(2*self.n)
for i in range(self.n):
self.t[self.n+i] = a[i]
for i in range(self.n-1, 0, -1):
self.t[i] = max(self.t[i << 1], self.t[(i << 1) | 1])
def query(self, l, r):
ans = -1e9; l += self.n; r += self.n + 1
while l<r:
if (l & 1): ans = max(ans, self.t[l]); l += 1
if (r & 1): r -= 1; ans = max(ans, self.t[r])
l >>= 1; r >>= 1
return ans
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for tidx in range(t):
n, m = [int(y) for y in input().split()]
ex = [0]*n
ep = [0]*n
f = [0]*(3*n)
d2 = dict()
for i in range(n):
x, p = [int(y) for y in input().split()]
f[3*i] = x-p
f[3*i+1] = x
f[3*i+2] = x+p
d2[x-p] = d2.get(x-p, 0) + 1
d2[x] = d2.get(x, 0) - 2
d2[x+p] = d2.get(x+p, 0) + 1
ex[i] = x
ep[i] = p
f = list(set(f))
l = len(f)
f.sort()
d = dict()
for i in range(l):
d[f[i]] = i
q = [0]*(l)
q3 = [0]*(l)
q4 = [0]*(l)
s = 0
for i in range(l-1):
s += d2[f[i]]
q[i+1] = q[i] + s*(f[i+1]-f[i])
q3 = [q[i] + n-f[i] for i in range(l)]
q4 = [q[i] + f[i] for i in range(l)]
m1 = [0]*l
m2 = [0]*l
m3 = SegTree(q3)
m4 = SegTree(q4)
m1[0] = q[0]
for i in range(l-1):
m1[i+1] = max(m1[i], q[i+1])
m2[l-1] = q[l-1]
for i in range(l-1, 0, -1):
m2[i-1] = max(m2[i], q[i-1])
ans = ["0"]*n
for i in range(n):
x = ex[i]
p = ep[i]
g = max(m1[d[x-p]], m2[d[x+p]], m3.query(d[x-p], d[x]) - (n-x) - p, m4.query(d[x], d[x+p]) - x - p)
if g <= m: ans[i] = "1"
print("".join(ans))
590. N-ary Tree Postorder Traversal | 589. N-ary Tree Preorder Traversal |
1299. Replace Elements with Greatest Element on Right Side | 1768. Merge Strings Alternately |
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |
1822. Sign of the Product of an Array | 1464. Maximum Product of Two Elements in an Array |
1323. Maximum 69 Number | 832. Flipping an Image |
1295. Find Numbers with Even Number of Digits | 1704. Determine if String Halves Are Alike |
1732. Find the Highest Altitude | 709. To Lower Case |
1688. Count of Matches in Tournament | 1684. Count the Number of Consistent Strings |
1588. Sum of All Odd Length Subarrays | 1662. Check If Two String Arrays are Equivalent |
1832. Check if the Sentence Is Pangram | 1678. Goal Parser Interpretation |
1389. Create Target Array in the Given Order | 1313. Decompress Run-Length Encoded List |
1281. Subtract the Product and Sum of Digits of an Integer | 1342. Number of Steps to Reduce a Number to Zero |
1528. Shuffle String | 1365. How Many Numbers Are Smaller Than the Current Number |
771. Jewels and Stones | 1512. Number of Good Pairs |
672. Richest Customer Wealth | 1470. Shuffle the Array |